package com.ebelter.myehc.ui.activitys;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.ebelter.btcomlib.utils.ToastUtil;
import com.ebelter.myehc.R;
import com.ebelter.myehc.models.ota.OtaManager;


public class DfuUpdateActivity extends Activity{


    public static final String TAG = "DfuUpdateActivity";

    public static final String SRC_MAC = "SRC_MAC";
    public static final String OTA_MAC = "OTA_MAC";

    public String srcMac;
    public String otaMac;

    private OtaManager mOtaManager;

    private TextView logtv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.shhupdate);
        srcMac = getIntent().getStringExtra(SRC_MAC);
        otaMac = getIntent().getStringExtra(OTA_MAC);

        if (TextUtils.isEmpty(srcMac)||TextUtils.isEmpty(otaMac)){
            LogUtils(TAG,"------DfuUpdateActivity---srcMac="+srcMac+"---otaMac="+otaMac);
            throw new NullPointerException("----ota升级地址出错");
        }

        logtv=findViewById(R.id.logtv);


    }


    private void addLog(String msgLog){
        String srclog = logtv.getText().toString();
        if (!TextUtils.isEmpty(srclog)&&srclog.length() > 5000){
            srclog=srclog.substring(0,4998);
        }
        srclog=msgLog+"\n"+srclog;
        if (logtv!=null)logtv.setText(srclog);
    }


    @Override
    protected void onResume() {
        super.onResume();
        mOtaManager.registerProgressListener(this);
        mOtaManager.startUpdate2(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        mOtaManager.unRegisterProgressListener(this);
    }


    public static void LogUtils(String tag,String msg){
        Log.i(tag,msg);
        ToastUtil.show(msg);
    }




    public void one2(View view) {
        mOtaManager.startUpdate(this);
    }
}
